<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>混入 基础-选项合并</title>
</head>

<body>
    <div id="app"></div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>

        var myMixin = {
            created: function () {
                //全局混入                
                var myOption = this.$options.myOption
                if (myOption) {
                    console.log(myOption)
                }
                console.log('混入');
            },
            methods: {
                foo: function () {
                    console.log('foo')
                },
                conflicting: function () {
                    console.log('from myMixin')
                }
            }
        };


        var Vm = new Vue({
            mixins: [myMixin],

            
            myOption:'我的世界!',
            created: function () {
                //选项合并 发生冲突时以组件数据优先

                //同名钩子函数将合并为一个数组，因此都将被调用。另外，混入对象的钩子将在组件自身钩子之前调用

                //值为对象的选项，例如 methods、components 和 directives，将被合并为同一个对象。两个对象键名冲突时，取组件对象的键值对
                console.log('组件')
            },
            methods: {
                bar: function () {
                    console.log('bar')
                },
                confilicting:function(){
                    console.log('from self')
                }
            }
        });


        Vm.foo();
        Vm.bar();
        Vm.confilicting();


    </script>
</body>

</html>